package IO流.IO流操作.处理流.数据流;

import java.io.*;

/**
 * 数据流
 * <p>
 * 1.写出后读取
 * 2.读取顺序与写出顺序一致
 * <p>
 * DataInputStream
 * DataOutputStream
 */
public class DataTest {
    public static void main(String[] args) throws IOException {
        //写出
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(byteArrayOutputStream));
        //操作数据类型
        dos.writeUTF("编码辛酸泪");
        dos.writeInt(18);
        dos.writeBoolean(false);
        dos.writeChar('a');
        dos.flush();
        byte[] data = byteArrayOutputStream.toByteArray();

        //读取
        DataInputStream dis = new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(data)));
        //顺序与写出一致
        String msg = dis.readUTF();
        int age = dis.readInt();
        boolean bool = dis.readBoolean();
        char a = dis.readChar();
        System.out.println(a);
    }
}
